﻿//paymentInfo
$("#paymentInfo").on('click', function () {
    var fullname = document.getElementById("fullname").innerText;
    var fullnameS = fullname.replace(/\s/g, '&nbsp;');
    var sdt = document.getElementById("sdt").innerText;
    var email = document.getElementById("email").innerText;
    $.Dialog({
        overlay: true,
        shadow: true,
        flat: true,
        title: 'Thanh Toán',
        content: '',
        padding: 10,
        onShow: function (_dialog) {
            var content = '<label>Tên đầy đủ</label>' +
                '<div class="input-control text"><input type="text" name="userName" id="username" value= ' + fullnameS + '><button class="btn-clear"></button></div> ' +
            '<label>Số điện thoại </label>' + '<div class="input-control text">  <input type="text" name="sdt" id="sdt" value=' + sdt + '>     <button class="btn-clear"></button></div> ' +
             '<label>Email </label>' + '<div class="input-control text">  <input type="text" name="email" id="email" value=' + email + '>     <button class="btn-clear"></button></div> ' +
             '<div class="form-actions">' +
            '<button class="button" onclick="checkLogin()">Thanh Toán</button> ' +
            '<button class="button" type="button" onclick="$.Dialog.close()">Đóng</button> ' +
            '</div>';
            $.Dialog.title("Thanh Toán");
            $.Dialog.content(content);
            $.Metro.initInputs();
        }
    });
});

//TAO EMBED WINDOW
$("#createWindowYoutube").on('click', function () {
    $.Dialog({
        overlay: false,
        shadow: true,
        flat: false,
        icon: '<img src="images/excel2013icon.png">',
        title: 'KUNGFU PANDA 3D',
        content: '',
        onShow: function (_dialog) {
            var html = [
                '<iframe width="640" height="480" src="//www.youtube.com/embed/PXi3Mv6KMzY" frameborder="0" allowfullscreen></iframe>'
            ].join("");

            $.Dialog.content(html);
        }
    });
});

//BOOK GHE
///Xu li khi cilick vao 1 o
function registerOnSeatClicked(cell) {

    cell.click(function () {
        cell.toggleClass('seat_choose');
        var chairs = document.getElementsByClassName('seat_choose');
        //xu li 10 ghe dc chon
        if (chairs.length <= 10) {

            var pos = "";
            var chairId = "";
            var totalPrice = 0;
            var chairTypeR, chairType;
            for (var i = 0; i < chairs.length; i++) {
                //lay ra chuoi vi tri ghe
                pos = chairs[i].innerText + " " + pos;
                //lay ra chuoi id ghe
                chairId = chairs[i].children[0].innerText + " " + chairId;
                //thanh toan dua tren loai ghe
                chairTypeR = chairs[i].children[1].innerText;
                chairType = $.trim(chairTypeR);
                if (chairType == "Single") {
                    totalPrice = 60000 + totalPrice;
                }
                if (chairType == "Vip") {
                    totalPrice = 70000 + totalPrice;
                }
                if (chairType == "Couple") {
                    totalPrice = 90000 + totalPrice;
                }
            }
            //
            var posTxt = document.getElementById('picked');
            var chairIdTxt = document.getElementById('getId');
            var priceTxt = document.getElementById('giaTien');
            posTxt.innerHTML = pos;
            chairIdTxt.innerHTML = chairId;
            priceTxt.innerHTML = totalPrice;
            document.getElementById("thanhToan").appendChild(posTxt);
            document.getElementById("thanhToan").appendChild(chairIdTxt);
            document.getElementById("thanhToan").appendChild(priceTxt);
        } else { alert('enough'); cell.toggleClass('seat_choose'); }

    });
}
//Xac dinh vi tri tung o
function addRowHandlers() {
    var table = document.getElementById("desk");

    for (i = 0; i < table.rows.length; i++) {
        for (j = 0; j < table.rows[i].cells.length; j++) {
            var cell = $(table.rows[i].cells[j]);
            //chay ham khi click vao o
            registerOnSeatClicked(cell);
        };

    }

}

//Load List theater when choose a film-nguyenht
function loadTheaterByFilmId(idOfFilm) {
    $.ajax({
        url: "/Schedule/TheatersByFilm",
        type: "GET",
        data: { filmId: idOfFilm },
        success: function (data) {
            $('#listTheater').html(data);
        },
        error: function (data) {
            alert("fail");
        }
    });
}

//Load list showtime when choose a theater
function loadShowTimeByTheaterId(idOfTheater) {
    $.ajax({
        url: "/Schedule/ShowTimeOfTheater",
        type: "GET",
        data: { theaterId: idOfTheater },
        success: function (data) {
            $('#listShowTime').html(data);
        },
        error: function (data) {
            alert("fail");
        }

    });
}
//LUU TRANG THAI
function getChair() {

};

//Submit payment
function payment() {
    var chairId = document.getElementById('getId').innerText;
    $('.seat_choose').toggleClass().addClass('seated');
    $.ajax({
        url: "/CheckOut/Payment",
        type: "GET",
        data: { listId: chairId },
        success: function (data) {
            $('#paymentInfomation').html(data);
        },
        error: function (data) {
            alert("fail");
        }
    }

    );

}

//chuyen trang 
function routing() {

}


